package com.sui.bigdata.rtcadmin.controller;

import com.sui.bigdata.rtcadmin.dto.JobConfigDto;
import com.sui.bigdata.rtcadmin.model.vo.CommonResponse;
import com.sui.bigdata.rtcadmin.service.JobConfigService;
import com.sui.bigdata.rtcadmin.util.CheckUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author YongChen
 * @date 2019/11/6 14:41
 * @description
 * @email yong_chen@sui.com
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/jobConfig")
@Slf4j
public class JobConfigController extends BaseController{

    @Autowired
    private JobConfigService jobConfigService;


    @GetMapping("/all")
    ResponseEntity all() {
        return new ResponseEntity<>(jobConfigService.queryAll() , HttpStatus.OK);
    }

    @GetMapping
    public CommonResponse one(@RequestParam("jobName")String appName){
        return CommonResponse.Builder.buildSuccess(jobConfigService.queryByAppName(appName));
    }

    @PostMapping
    public CommonResponse add(@RequestBody JobConfigDto jobConfigDto) throws Exception{
        jobConfigService.save(jobConfigDto);
        return CommonResponse.Builder.buildSuccess(null);
    }

    @PutMapping
    public CommonResponse update(@RequestBody JobConfigDto jobConfigDto){
        jobConfigService.updateAlarmInfo(jobConfigDto);
        return CommonResponse.Builder.buildSuccess(null);
    }

    @DeleteMapping
    public  CommonResponse delete(@RequestParam("jobName")String appName){
        jobConfigService.deleteByJobName(appName);
        return CommonResponse.Builder.buildSuccess(null);
    }


}
